<?php
	/**
	* 
	*/
	class VerifyLogin extends MX_Controller
	{
		
		function __construct()
		{
			parent::__construct();
			$this->load->helper(array("url","form"));
			$this->load->library(array("form_validation","my_layout","session"));
			$this->load->model("muser",'',TRUE);
			$this->my_layout->setLayout("layout/frontend");
		}
		function Login()
		{
			$this->form_validation->set_rules('username','UserName', 'trim|required|xss_clean');
			$this->form_validation->set_rules('password','Password', 'trim|required|xss_clean');
			if($this->form_validation->run() == FALSE)
			{
				 redirect(base_url()."index.php/home");
			}
			else
			{
				$name = $this->input->post("username");
				$pass = $this->input->post("password");
				$session = $this->muser->checkLogin($name, $pass);
				if($session)
				{
					if(!$this->my_auth->is_Active($session['id_user'])){
                    	$data['error'] = "Please check mail and active your account !";
                   		$this->my_layout->view("frontend/home", $data);
	                }
	                else
	                {	
	                      $data = array(
	                                    "username"  => $session['username'],
	                                    "userid"    => $session['id_user'],
	                                );
	                     $this->my_auth->set_userdata($data);
	                     redirect(base_url()."home/news");
	                }
				}
				else
				{
					$this->my_layout->view("frontend/home", array("error"=>"Username or Password wrong"));
				}
			}
		}
		function Logout()
		{
			 $this->my_auth->sess_destroy();
			 redirect(base_url()."home");
		}
	}
?>